package com.carkeeper.order.contorller;

import com.carkeeper.entity.PageResult;
import com.carkeeper.entity.Result;
import com.carkeeper.entity.StatusCode;
import com.carkeeper.order.pojo.PostSerOrder;
import com.carkeeper.order.pojo.SerOrder;
import com.carkeeper.order.service.SerOrderService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.Map;


@RestController
@RequestMapping("/serviceOrder")
@CrossOrigin
@Api(value = "服务订单")
public class SerOrderContorller {

    @Autowired
    private SerOrderService serOrderService;

    /**
     * 分页查询所有服务订单
     * @param currentpage 页数
     * @param pagesize 每页条数
     * @return
     */
    @GetMapping("/pageSerOrder")
    @ApiOperation(value = "分页查询所有服务订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentpage",value = "当前页"),
            @ApiImplicitParam(name = "pagesize",value = "每页条数")
    })
    public PageInfo<SerOrder> pageSerOrder(@RequestParam(name = "currentpage",required = false) Integer currentpage, @RequestParam(name = "pagesize",required = false) Integer pagesize) {
        PageInfo<SerOrder> serOrderPageInfo = serOrderService.pageSerOrder(currentpage, pagesize);
        return serOrderPageInfo;
    }

    /**
     * 分页查询未处理服务订单
     * @param currentpage 页数
     * @param pagesize 每页条数
     * @return
     */
    @ApiOperation(value = "分页查询未处理服务订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentpage",value = "当前页"),
            @ApiImplicitParam(name = "pagesize",value = "每页条数")
    })
    @GetMapping("/UntreatPageSerOrder")
    public PageResult<SerOrder> UntreatPageSerOrder(@RequestParam(name = "currentpage",required = false) Integer currentpage, @RequestParam(name = "pagesize",required = false) Integer pagesize) {
        PageResult<SerOrder> pageResult = serOrderService.UntreatPageSerOrder(currentpage, pagesize);
        return pageResult;
    }

    /**
     * 多条件查询
     * @param map
     * @return
     */
    @ApiOperation(value = "多条件查询")
    @GetMapping("/searchSerOrder")
    public PageInfo<SerOrder> searchSerOrder(@RequestParam Map map) {
        PageInfo<SerOrder> serOrderPageInfo = serOrderService.SearchSerOrder(map);
        return serOrderPageInfo;
    }

    /**
     * 查询订单详情
     * @param serOrderId
     * @return
     */
    @ApiOperation(value = "查询订单详情")
    @ApiImplicitParam(name = "serOrderId",value = "服务订单id",required = true)
    @GetMapping("/findPostSerOrderById")
    public Result<PostSerOrder> findPostSerOrderById(@RequestParam("serOrderId") BigInteger serOrderId) {
        PostSerOrder postSerOrder=serOrderService.findPostSerOrderById(serOrderId);
        if (postSerOrder == null) {
            return new Result<>(false, StatusCode.ERROR, "查询订单详情失败");
        } else {
            return new Result<>(true, StatusCode.OK, "查询订单详情成功",postSerOrder);
        }
    }

}
